package com.night.student.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.night.common.entity.PageBean;
import com.night.common.entity.student.Evaluate;
import com.night.common.entity.student.Score;
import com.night.common.entity.student.ScoreVo;
import com.night.student.mapper.ScoreMapper;
import com.night.student.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Mr.Wang
 * @ClassName: ScoreServiceImpl
 * @Description: //TODO
 * @date: 2022/10/19-20:23
 */
@Service
public class ScoreServiceImpl implements ScoreService {
    @Autowired
    ScoreMapper scoreMapper;

    @Override
    public PageBean<List<Score>> getScoreByCondition(ScoreVo scoreVo) {
        int pageSize = 10;
        PageBean<List<Score>> pageBean = new PageBean<>();
        Page p = PageHelper.startPage(scoreVo.getPage(),pageSize);
        Score score = scoreVo.getScore();
        if(score.getTerm()==null){
            score.setTerm("");
        }
        List<Score> data = scoreMapper.getScoreByCondition(score);
        pageBean.setData(data);
        pageBean.setCurrPage(scoreVo.getPage());
        pageBean.setPageSize(pageSize);
        pageBean.setTotalNum((int) p.getTotal());
        pageBean.setTotalPages(p.getPages());
        return pageBean;
    }

    @Override
    public void insert(Score score) {
        scoreMapper.insert(score);
    }

    @Override
    public void adds(List<Score> scores) {
        scoreMapper.adds(scores);
    }

    @Override
    public void addSelectScore(Score score) {
        scoreMapper.addSelectScore(score);
    }
}
